package com.zjitc.controller;

import com.zjitc.model.Category;
import com.zjitc.model.Product;
import com.zjitc.service.CategoryService;
import com.zjitc.service.ProductService;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/26 14:28
 * @description:
 */
@Controller
public class IndexController {

  @Autowired
  private CategoryService categoryService;

  @Autowired
  private ProductService productService;

  @RequestMapping("/index")
  public String showIndex(HttpSession session) {
    List<Category> clist=categoryService.findAllCategory();
    session.setAttribute("clist",clist);

    List<Product> newProduct=productService.findAllProduct();
    List<Product> productList=new ArrayList<>();
    for(Product p:newProduct)
    {
      if(p.getIs_hot()==1)
      {
        productList.add(p);
      }
    }
    session.setAttribute("hotProduct",productList);
    session.setAttribute("newProduct",newProduct);
    return "/WEB-INF/user/index.jsp";
  }

}
